<template>
  <div v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="12">
          <el-form-item :label="$t('会议主题')" prop="name">
            <el-input v-model="form.name" size="small" :placeholder="$t('会议主题')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('使用人')" prop="place">
            <el-input v-model="form.place" size="small" :placeholder="$t('使用人')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('地点')" prop="phone">
            <el-input v-model="form.phone" size="small" :placeholder="$t('地点')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('会议室')" prop="phone">
            <el-input v-model="form.phone" size="small" :placeholder="$t('会议室')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('会议日期')" prop="phone">
            <el-input v-model="form.phone" size="small" :placeholder="$t('会议日期')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('时间段')" prop="phone">
            <el-input v-model="form.phone" size="small" :placeholder="$t('时间段')" />
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item :label="$t('是否有电话会议')">
            <el-radio-group v-model="form.callMeeting">
              <el-radio
                v-for="dict in callMeetingOptions"
                :key="dict.dictValue"
                :label="dict.dictValue"
              >{{ $t(dict.dictLabel) }}</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('是否有视频会议')">
            <el-radio-group v-model="form.videoMeeting">
              <el-radio
                v-for="dict in videoMeetingOptions"
                :key="dict.dictValue"
                :label="dict.dictValue"
              >{{ $t(dict.dictLabel) }}</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <SaveBtn has-permi="oa:meetingroom" />
    </div>
  </div>
</template>

<script>
    import { saveOaMeetingRoom } from '@/api/oa/meeting/oaMeetingRoom'
    export default {
        props: {
          oaMeetingRoomData: {
            type: [Array, Object],
            default: null
          }
        },
        data() {
            return {
                // 是否有电话会议字典
                callMeetingOptions: [], // 是否有视频会议字典
                videoMeetingOptions: [], // 表单参数
                form: {},
                loading: false,
                // 表单校验
                rules: {
                  name: [
                    { required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] }
                  ],
                  place: [
                    { required: true, message: this.$t('必填信息'), trigger: ['blur', 'change'] }
                  ]
                }
            }
        },
        watch: {

					oaMeetingRoomData: {
							immediate: true, // 很重要！！！
							handler(val) {
								this.form = !val ? {} : val
							}
						}

        },
        created() {
          this.getDicts('sys_yes_no').then(response => {
              this.callMeetingOptions = response.data
          })
          this.getDicts('sys_yes_no').then(response => {
              this.videoMeetingOptions = response.data
          })
        },
        methods: {
            // 取消按钮
            cancel() {
                this.$parent.$parent.open = false
                this.$parent.$parent.reset()
            },
            /** 提交按钮 */
            submitForm: function() {
                this.$refs['form'].validate(valid => {
                    if (valid) {
                        this.loading = true
                        saveOaMeetingRoom(this.form).then(response => {
                          if (response.code === 200) {
                            this.msgSuccess(this.$t('保存成功'))
                            this.$parent.$parent.open = false
                            this.$parent.$parent.getList()
                          } else {
                            this.msgError(response.msg)
                          }
                          this.loading = false
                        }).catch(() => {
                          this.loading = false
                        })
                    } else {
                      this.locationError(document)
                    }
              })
           }

        }

    }
</script>
